package com.xugou.service.Impl;

import com.xugou.dao.UserDao;
import com.xugou.pojo.User;
import com.xugou.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.util.List;

public class UserServiceImpl implements UserService {

    @Autowired
    @Qualifier("userDao")
    private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }


    //获取所有用户信息
    public List<User> getUserList() {
        List<User> userList = userDao.getUserList();
        return userList;
    }

    //通过用户名获取用户
    public User getUserByname(String name){

        if (name!=null){
            User userByName = userDao.getUserByName(name);
            return userByName;
        }else {
            return null;
        }
    }

    //检查用户名是否存在
    public boolean checkUsername(String username) {
        //验证用户是否存在
        User user = userDao.getUserByName(username);
        if (user!=null){
            return true;
        }else {
            return false;
        }
    }



    //判断用户名和密码是否一致,返回ture or false
    public boolean judgeLoginSuccess(String name,String pwd){
        User userByName = userDao.getUserByName(name);
        String pwdDao = userByName.getUserPwd();
        if (pwdDao.equals(pwd)){
            return true;
        }else {
            return false;
        }
    }

    //修改密码
    public int updateUserInfo(User user) {
        if(user != null) {
            int i = userDao.updateUserInfo(user);
            return i;
        }else{
            return 0;
        }
    }
}
